package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.SceneIntroduce;
import cn.wolfcode.trip.base.mapper.SceneIntroduceMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ISceneIntroduceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SceneIntroduceServiceImpl implements ISceneIntroduceService {
    @Autowired
    private SceneIntroduceMapper introduceMapper;

    @Override
    public PageInfo<SceneIntroduce> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo<>(introduceMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(SceneIntroduce entity) {
        if (entity.getCommend().getId() == null) {
            introduceMapper.insert(entity);
        } else {
            introduceMapper.updateByPrimaryKey(entity);
        }

    }

    @Override
    public SceneIntroduce listIntroductionByCommendId(Long commendId) {
        return introduceMapper.selectIntroductionByCommendId(commendId);
    }
}
